#!/usr/bin/python3
try:
    t = int(input())
    for t1 in range(t):
        N, M, D = list(map(int, input().split()))
        ns = list(map(int, input().split()))
        ds = 0
        for i in ns:
            ds += i
        ms = []
        for i in range(M):
            ms.append(list(map(int, input().split())))
        if ds <= D:
            print('Case #{}: {}'.format(t1 + 1, '0'))
        else:
            ds = ds - D
            isOK = False
            temp = []
            for i in range(M):
                if ms[i][0] >= ds:
                    isOK = True
                    temp.append(ms[i][1])
            if isOK:
                temp.sort()
                print('Case #{}: {}'.format(t1 + 1, temp[0]))
            else:
                print('Case #{}: {}'.format(t1 + 1, 'QAQ'))
except ValueError:
    pass
except EOFError:
    pass
except MemoryError:
    pass
